<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>WinMenuSelectItem</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>WinMenuSelectItem</h1>

<p>Invokes a menu item from the menu bar of the specified window.</p>

<pre class="Syntax">WinMenuSelectItem, WinTitle, WinText, Menu [, SubMenu1, SubMenu2, SubMenu3, SubMenu4, SubMenu5, SubMenu6, ExcludeTitle, ExcludeText]</pre>
<h3>Parameters</h3>
<dl>

  <dt>WinTitle</dt>
  <dd><p>A window title or other criteria identifying the target window. See <a href="../misc/WinTitle.htm">WinTitle</a>.</p></dd>

  <dt>WinText</dt>
  <dd><p>If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if <a href="DetectHiddenText.htm">DetectHiddenText</a> is ON.</p></dd>

  <dt>Menu</dt>
  <dd><p>The name of the top-level menu, e.g. File, Edit, View. It can also be the position of the desired menu item by using 1&amp; to represent the first menu, 2&amp; the second, and so on.</p></dd>

  <dt>SubMenu1</dt>
  <dd><p>The name of the menu item to select or its position (see above).</p></dd>

  <dt>SubMenu2</dt>
  <dd><p>If <em>SubMenu1</em> itself contains a menu, this is the name of the menu item inside, or its position.</p></dd>

  <dt>SubMenu3</dt>
  <dd><p>Same as above.</p></dd>

  <dt>SubMenu4</dt>
  <dd><p>Same as above.</p></dd>

  <dt>SubMenu5</dt>
  <dd><p>Same as above.</p></dd>

  <dt>SubMenu6</dt>
  <dd><p>Same as above.</p></dd>

  <dt>ExcludeTitle</dt>
  <dd><p>Windows whose titles include this value will not be considered.</p></dd>

  <dt>ExcludeText</dt>
  <dd><p>Windows whose text include this value will not be considered.</p></dd>

</dl>

<h3>ErrorLevel</h3>
<p><span class="ver">[v1.1.04+]</span> This command is able to throw an exception on failure. For more information, see <a href="Catch.htm#RuntimeErrors">Runtime Errors</a>.</p>
<p><a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1 if there was a problem or 0 otherwise.</p>
<h3>Remarks</h3>
<p>For this command to work, the target window need not be active. However, some windows might need to be in a <a href="WinRestore.htm">non-minimized</a> state.</p>
<p>This command <strong>will not work</strong> with applications that use non-standard menu bars. Examples include Microsoft Outlook and Outlook Express, which use disguised toolbars for their menu bars. In these cases, consider using <a href="ControlSend.htm">ControlSend</a> or <a href="PostMessage.htm">PostMessage</a>, which should be able to interact with some of these non-standard menu bars.</p>
<p>The menu name parameters are not case sensitive (i.e. File-&gt;Save is the same as file-&gt;save) and the use of ampersand (&amp;) to indicate the underlined letter in a menu item is not necessary (i.e. &amp;File is the same as File).</p>
<p>The menu name parameters can also specify positions. This method exists to support menus that don't contain text (perhaps because they contain pictures of text rather than actual text). Position 1&amp; is the first menu item (e.g. the File menu), position 2&amp; is the second menu item (e.g. the Edit menu), and so on. Menu separator lines count as menu items for the purpose of determining the position of a menu item.</p>
<p>Window titles and text are case sensitive. Hidden windows are not detected unless <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> has been turned on.</p>

<h3>Related</h3>
<p><a href="ControlSend.htm">ControlSend</a>, <a href="PostMessage.htm">PostMessage</a></p>
<h3>Example</h3>
<pre class="NoIndent"><em>; This will select File-&gt;Open in Notepad:</em>
WinMenuSelectItem, Untitled - Notepad, , File, Open

<em>; Same as above except it's done by position vs. name:</em>
WinMenuSelectItem, Untitled - Notepad, , 1&amp;, 2&amp;</pre>

</body>
</html>
